//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.eResearch.RuntimeServices.Ontology
{
    using System;

    public static class OntologyMappingServiceExtensions
    {
        public static OntologyMappingService GetOntologyMappingService(this IServiceProvider serviceProvider)
        {
            OntologyMappingService service = (OntologyMappingService)serviceProvider.GetService(typeof(OntologyMappingService));
            if (service == null)
            {
                string message = "An OntologyMappingService could not be found in the runtime's list of services.";
                throw new InvalidOperationException(message);
            }

            return service;
        }

        public static bool TryGetOntologyMappingService(this IServiceProvider serviceProvider, out OntologyMappingService service)
        {
            service = (OntologyMappingService)serviceProvider.GetService(typeof(OntologyMappingService));
            return service == null ? false : true;
        }
    }
}
